package com.example.mobile2030606162zwh0618;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.text.BreakIterator;
import java.util.List;

public class UsersRViewAdapter extends RecyclerView.Adapter<UsersRViewAdapter.VireHolder> {
    private List<Users> list;
    public UsersRViewAdapter(List<Users>list){this.list=list;}

    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tvItemID,tvItemName,tvItemAge,tvItemScore;
        Button btnItemUpdate,btnMainDeletep;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvItemID=itemView.findViewById(R.id.tvItemId);
            tvItemName=itemView.findViewById(R.id.tvItemName);
            tvItemAge=itemView.findViewById(R.id.tvItemAge);
            tvItemScore=itemView.findViewById(R.id.tvItemScore);
            btnItemUpdate=itemView.findViewById(R.id.btnItemUpdate);
            btnMainDeletep=itemView.findViewById(R.id.btnMainDelete);
        }
    }
    @NonNull
    @Override
    public VireHolder onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_main_user,parent,false);
        return new VireHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull VireHolder holder, int position) {
        Users users=list.get(position);
        holder.tvItemId.setText(String.valueOf(users.get_id()));
        holder.tvItemName.setText(users.getName());
        holder.tvItemAge.setText(String.valueOf(users.getAge()));
        holder.tvItemScore.setText(String.valueOf(users.getScore()));

            }




    @Override
    public int getItemCount() {
        return list.size();
    }

    public class VireHolder extends RecyclerView.ViewHolder {
        public BreakIterator tvItemId;
        public BreakIterator tvItemName;
        public BreakIterator tvItemAge;
        public BreakIterator tvItemScore;
        public BreakIterator btnItemDelet;

        public VireHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}




